#coding=utf-8
from page.register_page import RegisterPage
import sys
# from util.get_code import GetCode
from log.user_log import UserLog

class RegisterHandle(object):
    def __init__(self,driver):
        self.driver = driver
        self.register_p = RegisterPage(self.driver)
        get_user_log = UserLog()
        self.loger = get_user_log.get_log()
    
    #输入用户名
    def send_user_name(self,username):
        self.loger.info("输入的手机号码是："+username)
        a01 = self.register_p.get_username_element()
        a01.clear()
        a01.send_keys(username)

    #输入密码
    def send_user_password(self,password):
        self.loger.info("输入的密码是："+password)
        a01 = self.register_p.get_password_element()
        a01.clear()
        a01.send_keys(password)

    def send_user_password_2(self,password_2):
        self.loger.info('输入的密码2是：'+password_2)
        a01 = self.register_p.get_password02_element()
        a01.clear()
        a01.send_keys(password_2)
    
    #输入验证码
    # def send_user_code(self,file_name):
    #     get_code_text = GetCode(self.driver)
    #     code = get_code_text.code_online(file_name)
    #     self.register_p.get_code_element().send_keys(code)

    # 输入验证码
    def send_user_code(self,code):
        self.loger.info('输入验证码是：'+code)
        a01 = self.register_p.get_code_element()
        a01.clear()
        a01.send_keys(code)
    
    #获取文字信息
    # def get_user_text(self,info,user_info):
    #     try:
    #         if info == 'user_email_error':
    #             text = self.register_p.get_email_error_element().text
    #         elif info == 'user_name_error':
    #             text = self.register_p.get_name_error_element().text
    #         elif info == 'password_error':
    #             text = self.register_p.get_password_error_element().text
    #         elif info == 'code_text_error':
    #             text = self.register_p.get_code_error_element().text
    #         else:
    #             text = self.register_p.get_code_element().text
    #     except:
    #         result = None
    #     else:
    #         if text == user_info:
    #             result = True
    #         else:
    #             result = False
    #     return result
    # 获取文字信息
    def get_user_text(self,info,user_info):

        if info == 'user_email_error':
            text = self.register_p.get_email_error_element().text
        elif info == 'user_name_error':
            text = self.register_p.get_name_error_element().text
        elif info == 'password_error':
            text = self.register_p.get_password_error_element().text
        elif info == 'code_text_error':
            text = self.register_p.get_code_error_element().text
        else:
            text = 'message：【该元素信息"%s"不存在！】'%(info)
        return text

    #点击注册按钮
    def click_register_button(self):
        self.register_p.get_button_element().click()
    
    #获取注册按钮文字
    def get_register_text(self):
        return self.register_p.get_button_element().text


        